﻿Partial Public Class PrivacyWindow

    Public Sub New()
        _ViewModel = New PrivacyWindowViewModel

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        App.DefaultWindowStyle.Attach(Me)
    End Sub


    Private _ViewModel As PrivacyWindowViewModel
    Public ReadOnly Property ViewModel() As PrivacyWindowViewModel
        Get
            Return _ViewModel
        End Get
    End Property

    Protected Sub OnAddVisibleContactClick(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Dim identifier As String

        Try
            identifier = NewVisibleContact.Text

            ViewModel.AddVisibleContact(identifier)
        Catch ex As Exception
            Core.Kernel.Exceptions.PublishException(ex)
        End Try
    End Sub

    Protected Sub OnRemoveVisibleContactClick(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Dim view As ComponentModel.ICollectionView
        Dim contact As ContactViewModel

        Try
            view = CollectionViewSource.GetDefaultView(ViewModel.VisibleContacts)
            contact = DirectCast(view.CurrentItem, ContactViewModel)

            ViewModel.RemoveVisibleContact(contact)
        Catch ex As Exception
            Core.Kernel.Exceptions.PublishException(ex)
        End Try
    End Sub

    Protected Sub OnAddInvisibleContactClick(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Dim identifier As String

        Try
            identifier = NewInvisibleContact.Text

            ViewModel.AddInvisibleContact(identifier)
        Catch ex As Exception
            Core.Kernel.Exceptions.PublishException(ex)
        End Try
    End Sub

    Protected Sub OnRemoveInvisibleContactClick(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Dim view As ComponentModel.ICollectionView
        Dim contact As ContactViewModel

        Try
            view = CollectionViewSource.GetDefaultView(ViewModel.InvisibleContacts)
            contact = DirectCast(view.CurrentItem, ContactViewModel)

            ViewModel.RemoveInvisibleContact(contact)
        Catch ex As Exception
            Core.Kernel.Exceptions.PublishException(ex)
        End Try
    End Sub

    Protected Sub OnAddIgnoreContactClick(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Dim identifier As String

        Try
            identifier = NewIgnoreContact.Text

            ViewModel.AddIgnoreContact(identifier)
        Catch ex As Exception
            Core.Kernel.Exceptions.PublishException(ex)
        End Try
    End Sub

    Protected Sub OnRemoveIgnoreContactClick(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Dim view As ComponentModel.ICollectionView
        Dim contact As ContactViewModel

        Try
            view = CollectionViewSource.GetDefaultView(ViewModel.IgnoredContacts)
            contact = DirectCast(view.CurrentItem, ContactViewModel)

            ViewModel.RemoveIgnoreContact(contact)
        Catch ex As Exception
            Core.Kernel.Exceptions.PublishException(ex)
        End Try
    End Sub

End Class
